package com.yh.homestay.service.impl;

import com.yh.homestay.dao.CapitalGoodsMapper;
import com.yh.homestay.dao.LogListMapper;
import com.yh.homestay.dao.SysLogMapper;
import com.yh.homestay.pojo.CapitalGoods;
import com.yh.homestay.pojo.SysLog;
import com.yh.homestay.service.EchartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class EchartsServiceImpl implements EchartsService {
    @Autowired
    private LogListMapper logListMapper;//只做展示和模糊查询mapper
    @Autowired
    private CapitalGoodsMapper capitalGoodsMapper;
    @Override
    public Map echartsShowsItems() {

        Map map=new HashMap();

        Map<String,String> addLog=new HashMap<>();

        Map<String,String> delLog=new HashMap<>();
        Map<String,String> editLog=new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        String end=sdf.format(c.getTime());
        c.add(Calendar.DATE, - 7);
        Date time = c.getTime();
        String start = sdf.format(time);
        addLog.put("start",start);
        addLog.put("end",end);
        addLog.put("logAccessModule","商品管理");
        addLog.put("logAccessFun","添加商品");
        List<SysLog> add=logListMapper.listLogs(addLog);
        delLog.put("start",start);
        delLog.put("end",end);
        delLog.put("logAccessModule","商品管理");
        delLog.put("logAccessFun","删除商品");
        List<SysLog> del=logListMapper.listLogs(delLog);
        editLog.put("start",start);
        editLog.put("end",end);
        editLog.put("logAccessModule","商品管理");
        editLog.put("logAccessFun","修改商品");
        List<SysLog> edit=logListMapper.listLogs(delLog);

        if (add.size()>0){
            map.put("添加商品",add.size());
        }else {
            map.put("添加商品",0);
        }

        if (del.size()>0){
            map.put("删除商品",del.size());
        }else {
            map.put("删除商品",0);
        }
        if (edit.size()>0){
            map.put("修改商品",edit.size());
        }else {
            map.put("修改商品",0);
        }
        return map;
    }

    @Override
    public List<CapitalGoods> echartsShowsGoods() {
        List<CapitalGoods> capitalGoods = capitalGoodsMapper.selectAll();
        return capitalGoods;
    }
}
